package com.hadwinling.alogriithm.apilearn.source;

import org.apache.flink.api.common.serialization.SimpleStringSchema;
import org.apache.flink.streaming.api.datastream.DataStream;

import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumer;

import java.util.Properties;

/**
 * @description:
 * @author: hadwinling
 * @time: 2021/2/19 上午11:47
 */
public class SourceTest1_Kafka {
    public static void main(String[] args) throws Exception {
        //创建执行文件
        StreamExecutionEnvironment executionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment();
        executionEnvironment.setParallelism(1);

        Properties properties = new Properties();
        properties.setProperty("bootstrap.servers", "localhost:9092");
        properties.setProperty("group.id", "consumer-group");
        properties.setProperty("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
        properties.setProperty("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
        properties.setProperty("auto.offset.reset", "latest");

        DataStream<String> dataStream = executionEnvironment.addSource( new FlinkKafkaConsumer<String>("sensor", new SimpleStringSchema(), properties));


        // 打印输出
//        stringDataStreamSource.print();

        // 执行
        executionEnvironment.execute();
    }
}
